package org.zjt.thread.interrupt;

import java.time.LocalDateTime;

/**
 * Description:
 *
 * @author juntao.zhang
 * Date: 2018-05-31 下午11:46
 * @see
 */
public class InterruptTest {

    public static void main(String[] args)   {


        Thread thread = new Thread(() -> {
            try {
                for (int i = 0; i < 5; i++) {
                    if (i % 2 == 0)
                        System.err.println(Thread.interrupted() + "    ");
                    System.err.println(LocalDateTime.now());
                    Thread.sleep(3000);
                }
            } catch (InterruptedException e) {
                System.out.println("只有抛出中断异常的操作才可以被中断");
                throw new RuntimeException();
            }
        });
        thread.start();
        thread.interrupt();
    }
}
